-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path[...slug].tsx
More file actions
79 lines (72 loc) · 2.37 KB
/
[...slug].tsx
File metadata and controls
79 lines (72 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { ProcessWithTemplate } from '@Components/service'
import { publishRecord } from '@podlite/publisher'
import { getTextContentFromNode } from '@podlite/schema'
import Head from 'next/head'
import { contentData } from 'src/serverside'
import { IndexProps } from '.'
import { getSiteInfo } from '../utils'
export default function AnyPage(params) {
const { siteTitle, favicon, footer, item, template } = params
if (template) {
item.template = template
}
// wrap all elements and add line link info
return (
<>
<Head>
<title>
{(item as publishRecord).title} - {siteTitle}
</title>
<meta
name="description"
content={
item.description
? getTextContentFromNode(item.description)
: siteTitle + ' ' + (item as publishRecord).title
}
/>
<link rel="shortcut icon" href={`/${favicon}`} />
</Head>
<main>{ProcessWithTemplate(item, footer)}</main>
</>
)
}
export async function getStaticPaths() {
const paths = contentData()
.filter(({ publishUrl }) => publishUrl !== '/')
.filter(({ publishUrl }) => Boolean(publishUrl))
.map(({ publishUrl }) => {
const slug = publishUrl.split('/').slice(1)
return {
params: {
slug,
},
}
})
return { paths, fallback: false }
}
export async function getStaticProps({ params }) {
const { slug } = params
const checkSlug =
slug =>
({ publishUrl }) => {
const url = '/' + slug.join('/')
return publishUrl === url
}
const item: any = contentData().find(checkSlug(slug))
const allData = item.type !== 'page' ? contentData().filter(({ type = '' }: any) => type !== 'page') : contentData()
const articleIndex = allData.findIndex(checkSlug(slug))
const { title: siteTitle, favicon, templateFile }: IndexProps = getSiteInfo()
let template = null
const template_file = item.template_file || templateFile || 'defaultTemplate/defaultSiteTemplate.podlite'
if (template_file) {
//@ts-ignore
template = contentData().find(({ file }) => file.endsWith(template_file)) || null
if (!template) {
console.error(`Template not found. Processed file: ${item.file} Template file:${template_file}`)
process.exit(1)
}
}
const footer = getSiteInfo().footer
return { props: { footer, item, template, siteTitle, favicon } }
}